﻿Public Class clsInhMaszyna
    Inherits clsMaszyna

#Region "Attributes"

    Dim mvarMaszyna As New Collection(Of clsMaszyna)
    Dim mvarGrupaMaszyny As New clsGrupaMaszyny

#End Region

#Region "Properties"

    Public Property Maszyna() As Collection(Of clsMaszyna)
        Get
            Return mvarMaszyna
        End Get
        Set(ByVal value As Collection(Of clsMaszyna))
            mvarMaszyna = value
        End Set
    End Property

    Public Property GrupaMaszyny() As clsGrupaMaszyny
        Get
            Return mvarGrupaMaszyny
        End Get
        Set(ByVal value As clsGrupaMaszyny)
            mvarGrupaMaszyny = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()

        mvarMaszyna = New Collection(Of clsMaszyna)

    End Sub

    Public Sub New(ByVal ID As Integer, ByVal lvarDbHolder As clsDataBase)

        MyBase.New(ID, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarGrupaMaszyny = New clsGrupaMaszyny(CStr(MyBase.GrupaMaszynyId), lvarDbHolder, VAR_ERROR_HANDLER)
    End Sub

    Public Sub Szukaj(ByVal lvarDbHolder As clsDataBase, ByRef ErrorHandler As clsErrorHandler, ByVal Zapytanie As String)

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_maszyna", 1, VAR_ERROR_HANDLER)
            With lvarSqlRunner
                .AddParameter("p_zapytanie", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    mvarMaszyna.Add(New clsMaszyna(CInt(IIf(IsDBNull(lvarReader.Item("id")), -1, lvarReader.Item("id"))), lvarDbHolder, ErrorHandler))
                End While
            End If
        End If

    End Sub

    Shared Function PobierzWszystkieMaszynyGrupy(ByVal lvarDbHolder As clsDataBase, ByVal Zapytanie As Integer) As DataTable

        Dim lvarReader As OdbcDataReader = Nothing
        Dim lvarReturn As DataTable

        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_maszyna", 2, VAR_ERROR_HANDLER)

            With lvarSqlRunner
                .AddParameter("p_id_grupy_maszyny", CStr(Zapytanie))
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                lvarReturn = New DataTable
                lvarReturn.Load(lvarReader)
            End If

        End If

        Return lvarReturn

    End Function

#End Region

End Class
